﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Configuration;
using System.Text;
using SharingCenter.Web.Classes;

namespace SharingCenter.Web.Misc
{
    public partial class Contact : PageBase
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            lnkSend.Click += new EventHandler(lnkSend_Click);
        }

        void lnkSend_Click(object sender, EventArgs e)
        {
            MailAddress from = new MailAddress(ConfigurationManager.AppSettings["AccountMailAddress"]);
            MailAddress to = new MailAddress(ConfigurationManager.AppSettings["AccountMailAddress"]);
            MailMessage m = new MailMessage(from, to);
            m.ReplyTo = new MailAddress(txtEmail.Text.Trim().ToLower());
            m.SubjectEncoding = Encoding.UTF8;
            m.Subject = "反馈【" + ddlCategory.SelectedValue + "】";

            StringBuilder body = new StringBuilder();
            body.AppendFormat("<table style='width:600px;font-size:14px;font-family:tahoma, verdana;line-height:150%;border-collapse:collapse;' cellpadding='5'><tr><td valign='top' style='width:80px;'>发件人：</td><td valign='top'>{0}</td></tr><tr><td valign='top'>联系方式：</td><td>{2}</td></tr><tr><td valign='top'>内容：</td><td>{1}</td></tr></table>",
               txtName.Text.Trim() + " &lt;" + txtEmail.Text.Trim().ToLower() + "&gt;",
                txtContent.Text.Replace(Environment.NewLine, "<br/>"),
                txtContact.Text.Trim()
                );

            m.IsBodyHtml = true;
            m.Body = body.ToString(); //txtContent.Text.Trim() + Environment.NewLine + "联系方式：" + Environment.NewLine + txtContact.Text.Trim();
            m.BodyEncoding = Encoding.UTF8;

            SmtpClient client = new SmtpClient();

               

            try
            {
                client.Send(m);
                SetTopMostMessage("我们已收到您的意见，将尽快与您联系，谢谢！", true);
                RefreshPage();
            }
            catch (Exception ex) {
                msgError.Text = "抱歉，邮件发送错误。";
                msgError.Visible = true;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}